package com.liruo.treasureattic.service.url.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@Profile({"dev","test"})
@EnableSwagger2
public class Swagger2Configuration {
    @Bean
    public Docket docket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        .title("网址收藏站")
                        .description("统一管理网址")
                        .termsOfServiceUrl("https://github.com/liruohrh")
                        .contact(new Contact("liruo","https://github.com/liruohrh","xxx@qq.com"))
                        .version("1.0")
                        .build())
                .enable(true)
                .groupName("v1")
                .select()
                // 过滤路径
//                .paths(PathSelectors.a())
                // 指定扫描的包
                .apis(RequestHandlerSelectors.basePackage("com.liruo.treasureattic.service.url.controller"))
                .build();
    }

    @Configuration
    static class Knife4jMvcConfig implements WebMvcConfigurer {
        @Override
        public void addResourceHandlers(ResourceHandlerRegistry registry) {
            //  spring.web.resources.add-mappings=false 在关闭springmvc默认静态处理后需要自己加，不关就不用
            registry.addResourceHandler("/webjars/**")
                    .addResourceLocations("classpath:/META-INF/resources/webjars/")
                    .resourceChain(false);
            registry.addResourceHandler("/img/icons/**", "/*.html")
                    .addResourceLocations("classpath:/META-INF/resources/img/icons/", "classpath:/META-INF/resources/")
                    .resourceChain(false);
//            registry.addResourceHandler("/**")
//                    .addResourceLocations("classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/")
//                    .resourceChain(false);
        }
    }
}